<template>
  <div>
    <div class="public-common">
        <div class="public-title" style="text-indent: 20px;;">卫生检查记录列表</div>
        <div class="inline-btn">
          <label>检查部门：</label>
          <el-input v-model="searchdata.txtCheckDept"></el-input>
          <label>检查人：</label>
          <el-input v-model="searchdata.txtSupervisor"></el-input>
        </div>
        <div class="inline-btn">
          <label>检查结果：</label>
          <el-input v-model="searchdata.txtCheckResult"></el-input>
          <el-button type="primary" @click="searchBtn">搜索</el-button>
          <el-button type="primary" @click="addBtn">新建</el-button>
          <el-button type="warning" @click="deleteBtn">删除</el-button>
        </div>
        <div class="" style="margin:2%;">
          <el-table :data="tableData" border width="100%" @selection-change="handleSelectionChange">
            <el-table-column type="index" width="50" label=" " fixed="left"></el-table-column>
            <el-table-column type="selection"  width="55"></el-table-column>
            <el-table-column prop="CheckDept"  label="检查部门" ></el-table-column>
            <el-table-column prop="CheckTime"  label="检查时间" ></el-table-column>
            <el-table-column prop="Supervisor"  label="监察人" sortable></el-table-column>
            <el-table-column prop="CheckResult"  label="检查结果" sortable></el-table-column>
            <el-table-column prop="ImproveLimit"  label="整改期限(天数)" ></el-table-column>
            <el-table-column prop="RecheckMan"  label="复查人" ></el-table-column>
            <el-table-column prop="RecheckTime"  label="复查时间" ></el-table-column>
          </el-table>
          <el-pagination
            @size-change="handleSizeChange"  @current-change="handleCurrentChange"  :current-page="currentPage"
            :page-sizes="pagerange"  class="mt"  :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"  :total="totalnum"  ></el-pagination>
        </div>
    </div>
    <!--dialog-->
    <el-dialog title="卫生检查记录" :visible.sync="dialogVisible">
      <span>
        <el-form ref="formData" :model="formData" width="50%" style="margin-left:2%;" :rules="formRule" label-width="120px">
          <el-form-item label="检查部门：" prop="txtCheckOrgID">
            <el-select v-model="formData.txtCheckOrgID" placeholder="请选择检查部门">
              <el-option v-for="(t,i) in dutyList" :label="t" :key="i" :value="i"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="检查时间：" prop="txtCheckTime">
            <el-date-picker  clearable v-model="formData.txtCheckTime" format="yyyy-MM-dd" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
          <el-form-item label="监察人：" prop="txtSupervisor">
            <el-select v-model="formData.txtSupervisor" placeholder="请选择监察人">
              <el-option v-for="(t,i) in usedList" :label="t.name" :key="i" :value="t.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="检查结果：" prop="txtCheckResult">
            <el-select v-model="formData.txtCheckResult" placeholder="请选择检查结果">
              <el-option v-for="(t,i) in checkResult" :label="t" :key="i" :value="i"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="复查日期：" prop="txtRecheckTime">
            <el-date-picker  clearable v-model="formData.txtRecheckTime" format="yyyy-MM-dd" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
          <el-form-item label="整改期限(天)：" prop="txtImproveLimit">
            <el-input v-model="formData.txtImproveLimit" style="width: 220px;"></el-input>
          </el-form-item>
          <el-form-item label="复查人：" prop="txtRecheckMan">
            <el-select v-model="formData.txtRecheckMan" placeholder="请选择复查人">
              <el-option v-for="(t,i) in usedList" :label="t.name" :key="i" :value="t.id"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitData('formData',1)">应用</el-button>
        <el-button type="primary" @click="submitData('formData',2)">确 定</el-button>
        <el-button @click="cancelBtn('formData')">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {health,getAllUsedList} from '@/ajax';
import config from './Manage.js';
export default {
    data(){
        return {
          searchdata:{
            txtCheckDept:'',txtSupervisor:'',txtCheckResult:''
          },
          totalnum: 0,
          currentPage: 0,
          pagerange: [2, 10, 20, 50, 100],
          pagesize: 10,
          tableData:[],
          dialogVisible:false,
          formData:{txtCheckOrgID:'',txtCheckTime:'',txtSupervisor:'',txtCheckResult:'',
                    txtRecheckTime:'',txtImproveLimit:'',txtRecheckMan:''},
          formRule:{
            txtCheckOrgID:{required:true,message:'请选择检查部门',trigger:'blur'},
            txtSupervisor:{required:true,message:'请选择监察人',trigger:'blur'},
            txtCheckResult:{required:true,message:'请选择检查结果',trigger:'blur'},
            txtRecheckMan:{required:true,message:'请选择复查人',trigger:'blur'}
          },
          index:0,
          selection:[],
          config:config,
          dutyList:config.dutyList,
          assetsType:config.assetsType,
          AssetStatus:config.AssetStatus,
          checkResult:config.checkResult,
          usedList:[{'id':'123','name':'lily'}]
        }
    },
    mounted(){
      this.getHealthCheckList();
      this.getAllUsedList();
    },
    inject:['reload'],
    methods:{
      //getHealthCheckList,deleteHealthCheck,addHealthCheck
      searchBtn(){
        this.getHealthCheckList();
      },
      //
      handleSelectionChange(val){
        if(val){
          this.selection = [];
          for (let i in val) {
            this.selection.push(val[i]['CheckID'])
          }
        }
      },
      getHealthCheckList(){
        this.searchdata['page'] = this.pagesize;
        this.searchdata['rows'] = this.currentPage;
        this.tableData =config.assetsList;
        this.totalnum = this.tableData.length;
        /* health.getHealthCheckList(this.searchdata).then((res) => {
          if (res.data.code == '00000') {
            if(res.data.data.length > 0){
              this.tableData = res.data.data;
              this.totalnum = this.tableData.length;
            }else{
              this.tableData = [];
              this.totalnum = 0;
            }
          } else {
            this.$message(res.data.message);
          }
          }).catch(()=>{
            this.$message('服务器正忙，获取固定资产列表失败');
          }) */
      },
      //获取所有的领用人
      getAllUsedList(){
        getAllUsedList().then((res) => {
          if (res.data.code == '00000') {
            this.usedList = res.data.data;
          }
        })
      },
      //分页
      handleSizeChange(val){
          this.pagesize = val;
          this.getHealthCheckList();
      },
      handleCurrentChange(val){
          this.currentPage = val;
          this.getHealthCheckList();
      },
      addBtn(){
        this.dialogVisible = true;
      },
      cancelBtn(form){
        this.$refs[form].clearValidate();
        this.$refs[form].resetFields();
        this.dialogVisible=false;
      },
      deleteBtn(){
        if(this.selection.length <= 0){
          this.$message('请选择要操作的数据')
        }else{
           health.deleteHealthCheck({assetNo:JSON.stringify(this.selection)}).then((res) => {
              if (res.data.code == '00000') {
                this.reload()
              } else {
                this.$message(res.data.message);
              }
            }).catch(()=>{
              this.$message('服务器正忙，删除失败');
            })
        }
      },
      //进行添加（通过type区分应用确定，应用1确定2）
      submitData(form,type){
        this.$refs[form].validate((valid) => {
          if(valid){
            health.addHealthCheck(this.formData).then((res) => {
                if (res.data.code == '00000') {
                  if(type == 1){
                    this.$refs[form].resetFields();
                    /* this.formData = {txtCheckOrgID:'',txtCheckTime:'',txtSupervisor:'',txtCheckResult:'',
                    txtRecheckTime:'',txtImproveLimit:'',txtRecheckMan:''}; */
                  }else{
                    this.reload()
                  }
                } else {
                  this.$message(res.data.message);
                }
              }).catch(()=>{
                this.$message('服务器正忙，操作失败');
            })
          }else{
            return false
          }
        })
      }
    },
    watch:{

    }
}
</script>
<style lang="scss">
.public-common{
    .public-title{line-height: 30px;background-color: #deecfd;}
    .inline-btn{display: inline-flex;margin: 20px;
      label{width:100px;line-height: 32px;margin-left:10px;text-align: right;}
      .el-input{width: 170px;}
      .el-button{margin-left:10px;}
    }
    .el-form-item .el-input,.el-select,.el-date-picker{width: 200px !important;}
    .left{display: inline-block;;width:64%;float: left;}
    .right{display: inline-block;;width:35%;float: left;}
    .el-form .inline-btn{margin:unset;}
    .footer{
      width: 100%;
      display: inline-flex;
      margin-left: 72%;
    }
}
</style>
